# _*_ coding : utf-8 _*_
# @Time : 2023/12/11 16:00
# @Author : 韩宗森
# @File : 21_淘票票
# @Project : pythonProject

"""
# 去网页爬取数据

import urllib.request

url = 'https://dianying.taobao.com/cityAction.json?activityId&_ksTS=1702281545197_108&jsoncallback=jsonp109&action=cityAction&n_s=new&event_submit_doGetAllRegion=true'

headers = {
    # ':authority': 'dianying.taobao.com',
    # ':method': 'GET',
    # ':path': '/cityAction.json?activityId&_ksTS=1702281545197_108&jsoncallback=jsonp109&action=cityAction&n_s=new&event_submit_doGetAllRegion=true',
    # ':scheme': 'https',
    'Accept': 'text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01',
    # 'Accept-Encoding': 'gzip, deflate, br',
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'Bx-V': '2.5.6',
    'Cookie': 't=1ee53553b659aa46eec3af042d37349c; cna=14DYHbZ2PTgBASQOA1IsT0Qm; sgcookie=E100KCwUXrpwJKd90q2zQqq5HFZIyjTxwK8hrz7SlE2%2BK7kSC4WlCAQMyFgLV42uyEnU0y6VuEuyfAEbtRs24HmGsAMyGm8Dq9wUP6sqvNAL7R205G%2FpcM5HGVOp8sSx%2FclL; uc3=nk2=3B6d7lsMgxKElw%3D%3D&lg2=U%2BGCWk%2F75gdr5Q%3D%3D&id2=VWZ%2BwqCoAIxs&vt3=F8dD3CIdiT7kIbjT8e4%3D; lgc=%5Cu5F00%5Cu59CB%5Cu604B%5Cu7ED3%5Cu675F; uc4=id4=0%40V8e0jB3c0hJ%2FjJ81B4JtfJh0W%2FU%3D&nk4=0%403mqiVvifrYUsxFUfRI%2Bob6hVGQ8f; tracknick=%5Cu5F00%5Cu59CB%5Cu604B%5Cu7ED3%5Cu675F; thw=cn; cookie2=1860c33dab5ccc3c57ca31397cd2a690; v=0; _tb_token_=f81e753efe5ea; xlly_s=1; tb_city=450100; tb_cityName="xM/E/g=="; tfstk=egz93gmKR9XiEVJrxNIhgpvAJSChqPFNsRPWoxDMcJeLURCZmhqgDKHLN1kG0GyYv-wEjAaYgEhbG-5Zn1S3_5uqlTXuHaVa_GvhBc_kA5Lzfq6lEwxHOcWillxcAlSE7ipXba84ukh12SSGhFDfOfitFWIylEn6rcHSpvLfFyhOLYNspETf4VzuyjXHEYhDf6Cp0nosTp-1wIFhRfPS9Yft6n-qcXlKE6Cp0nosTXHl6KK20mGF.; l=fBLBbJJcPsYZ5RcvBOfwFurza77tTIRAguPzaNbMi9fPO3CH5XDCW1UPrQLMCnGVFs5HR3S3hc2kBeYBqC2sjqj4axom4rDmnmOk-Wf..; isg=BCAgnGcyURWXtO0z3Ev7BO9z8S7yKQTzdPNQs5oxuTvOlcC_QjsYg72rLT0VJbzL',
    'Referer': 'https://dianying.taobao.com/?spm=a1z21.3046609.city.200.32c0112aTKDY8D&city=450100',
    'Sec-Ch-Ua': '"Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"',
    'Sec-Ch-Ua-Mobile': '?0',
    'Sec-Ch-Ua-Platform': '"Windows"',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-origin',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
    'X-Requested-With': 'XMLHttpRequest'
}

# 请求对象的定制
request = urllib.request.Request(url=url, headers=headers)

response = urllib.request.urlopen(request)

content = response.read().decode('utf-8')

# 切割 取数据
content = content.split('(')[1].split(')')[0]

# 保存到本地
with open('21_淘票票.json', 'w', encoding='utf-8') as fp:
    fp.write(content)

"""
import json
import jsonpath

# 读取json文件
obj = json.load(open('21_淘票票.json','r',encoding='utf-8'))

# 解析数据 取出城市
city_list = jsonpath.jsonpath(obj,'$..regionName')

print(city_list)